package com.swzl.model.wx.controller;

import com.swzl.common.web.response.Result;
import com.swzl.common.web.response.ResultController;
import com.swzl.constant.ControllerConstant;
import com.swzl.model.wx.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @author fog
 * @date 2024年11月03日 13:33
 */

@RestController
@Api(tags = {"登录控制层"})
@RequestMapping(ControllerConstant.API_WX_PREFIX)
public class LoginController extends ResultController {

    @Resource
    private UserService userService;

    /**
     * 微信小程序登录接口
     *
     * @param params 前端传入
     * @return
     */
    @ResponseBody
    @PostMapping("login")
    @ApiOperation(value = "微信授权登录接口")
    public Result wxAutoLogin(@RequestBody Map<String, String> params) {

        String code = params.get("code");

        HashMap<String, String> result = userService.wxAutoLogin(code);

        return success(result);
    }

    /**
     * 手机号登录接口
     *
     * @param params 前端传入
     * @return
     */
    @ResponseBody
    @PostMapping("loginByPhone")
    @ApiOperation(value = "手机号授权登录接口")
    public Result phoneLogin(@RequestBody Map<String, String> params) {

        String code = params.get("code");

        HashMap<String, String> result = userService.wxAutoLogin(code);

        return success(result);
    }

    /**
     * 账号密码登录接口
     *
     * @param params 前端传入
     * @return
     */
    @ResponseBody
    @PostMapping("loginByPassword")
    @ApiOperation(value = "手机号授权登录接口")
    public Result passwordLogin(@RequestBody Map<String, String> params) {

        String code = params.get("code");

        HashMap<String, String> result = userService.wxAutoLogin(code);

        return success(result);
    }

}
